package de.baumann.browser.activitys.center

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.view.View
import com.umeng.socialize.bean.SHARE_MEDIA
import de.baumann.browser.R
import de.baumann.browser.activitys.AbstractShareActivity
import de.baumann.browser.iview.ITurnVipView
import de.baumann.browser.present.TurnVipPresenter
import de.baumann.browser.views.dialog.TurnVipSuccessDialog
import kotlinx.android.synthetic.main.activity_turn_vip.*
import kotlinx.android.synthetic.main.include_tool_bar.*


/**
 *@author:
 *@date:2019/7/2 14:49
 *@discription: 新用户成为 VIP
 */

class TurnVipActivity : AbstractShareActivity<ITurnVipView, TurnVipPresenter>(), ITurnVipView {

    private var canTurnVip = false
    private var licence = ""

    companion object {
        fun startTurnVipActivity(context: Context) {
            context.startActivity(Intent(context, TurnVipActivity::class.java))
        }
    }

    override fun getLayout(): Int {
        return R.layout.activity_turn_vip
    }

    override fun initView() {
        initToolbar(commToolBar, null)
        btnTurnVip.setOnClickListener {
            if (canTurnVip) {
                if (licence.isEmpty()) {
                    showShortToast(getString(R.string.please_return_to_reenter))
                } else {
                    presenter.licenceActive(licence)
                }
            } else {
                RequestLicenceActivity.startRequestLicenceActivity(mContext, 0)
            }
        }
    }

    override fun createPresenter(): TurnVipPresenter {
        return TurnVipPresenter()
    }

    override fun createView(): ITurnVipView {
        return this
    }

    override fun initData() {
        presenter.getLicenceCount()
    }

    @SuppressLint("SetTextI18n")
    override fun setUseableCount(count: String) {
        if (count.toInt() > 0) {
            canTurnVip = true
        }
        tvCanTurnLicence.text = "$count Licence"
    }


    override fun setUseableLicence(licence: String?) {
        if (licence != null) {
            this.licence = licence
        }
    }

    override fun turnVipSuccess() {
        TurnVipSuccessDialog(mContext, View.OnClickListener {
            displaySharePanel()
        }).show()
    }

    override fun onResult(share_media: SHARE_MEDIA?) {
        dimissSharePanel()
        finish()
    }
}
